using SM.core;
using SS;
using SS.core;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace TVSBH.doctor
{
	public class frmFindTmpPrescription : Form
	{
		private IContainer components = null;
		private DataGridView dgvBill;
		private Button btnClose;
		private DataGridView dgvProduct;
		private Button btnAddToBill;
		private ToolTip toolTip1;
		private Label lblCountBill;
		private TextBox txtID;
		private TextBox txtNote;
		private DataGridViewTextBoxColumn billID;
		private DataGridViewTextBoxColumn Note;
		private DataGridViewTextBoxColumn DateCreate;
		private DataGridViewTextBoxColumn DeseaseID;
		private DataGridViewTextBoxColumn productName;
		private DataGridViewTextBoxColumn productUnit;
		private DataGridViewTextBoxColumn productNumber;
		private DataGridViewTextBoxColumn ProductID;
		private DataGridViewTextBoxColumn ProductGuide;
		private Func objFunc = new Func();
		public string userName = "";
		public string fullName = "";
		public string currDeseaseName = "";
		public string currPid = "";
		public string strConnection = "";
		public string tmpUsage = "";
		private customers objCus = new customers();
		private products objProduct = new products();
		private Doctor objDoctor = new Doctor();
		public DataTable objProductTable = new DataTable();
		public bool OK = false;
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.components = new Container();
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmFindTmpPrescription));
			this.dgvBill = new DataGridView();
			this.btnClose = new Button();
			this.dgvProduct = new DataGridView();
			this.btnAddToBill = new Button();
			this.toolTip1 = new ToolTip(this.components);
			this.lblCountBill = new Label();
			this.txtID = new TextBox();
			this.txtNote = new TextBox();
			this.productName = new DataGridViewTextBoxColumn();
			this.productUnit = new DataGridViewTextBoxColumn();
			this.productNumber = new DataGridViewTextBoxColumn();
			this.ProductID = new DataGridViewTextBoxColumn();
			this.ProductGuide = new DataGridViewTextBoxColumn();
			this.billID = new DataGridViewTextBoxColumn();
			this.Note = new DataGridViewTextBoxColumn();
			this.DateCreate = new DataGridViewTextBoxColumn();
			this.DeseaseID = new DataGridViewTextBoxColumn();
			((ISupportInitialize)this.dgvBill).BeginInit();
			((ISupportInitialize)this.dgvProduct).BeginInit();
			base.SuspendLayout();
			this.dgvBill.AllowUserToAddRows = false;
			this.dgvBill.AllowUserToDeleteRows = false;
			this.dgvBill.AllowUserToOrderColumns = true;
			this.dgvBill.AllowUserToResizeColumns = false;
			this.dgvBill.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvBill.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvBill.BackgroundColor = Color.White;
			this.dgvBill.BorderStyle = BorderStyle.Fixed3D;
			this.dgvBill.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.dgvBill.Columns.AddRange(new DataGridViewColumn[]
			{
				this.billID,
				this.Note,
				this.DateCreate,
				this.DeseaseID
			});
			this.dgvBill.Cursor = Cursors.Hand;
			this.dgvBill.EnableHeadersVisualStyles = false;
			this.dgvBill.Location = new System.Drawing.Point(4, 7);
			this.dgvBill.MultiSelect = false;
			this.dgvBill.Name = "dgvBill";
			this.dgvBill.ReadOnly = true;
			this.dgvBill.RowHeadersVisible = false;
			this.dgvBill.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvBill.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvBill.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvBill.Size = new Size(675, 155);
			this.dgvBill.TabIndex = 41;
			this.dgvBill.DoubleClick += new EventHandler(this.dgvBill_DoubleClick);
			this.dgvBill.CellEnter += new DataGridViewCellEventHandler(this.dgvBill_CellEnter);
			this.btnClose.Cursor = Cursors.Hand;
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(192, 192, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new System.Drawing.Point(589, 436);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(90, 24);
			this.btnClose.TabIndex = 25;
			this.btnClose.Text = "Thoát [ESC]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.dgvProduct.AllowUserToAddRows = false;
			this.dgvProduct.AllowUserToDeleteRows = false;
			this.dgvProduct.AllowUserToOrderColumns = true;
			this.dgvProduct.AllowUserToResizeColumns = false;
			this.dgvProduct.AllowUserToResizeRows = false;
			dataGridViewCellStyle2.BackColor = Color.White;
			dataGridViewCellStyle2.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.dgvProduct.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle2;
			this.dgvProduct.BackgroundColor = Color.White;
			this.dgvProduct.BorderStyle = BorderStyle.Fixed3D;
			this.dgvProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvProduct.Columns.AddRange(new DataGridViewColumn[]
			{
				this.productName,
				this.productUnit,
				this.productNumber,
				this.ProductID,
				this.ProductGuide
			});
			this.dgvProduct.Cursor = Cursors.Hand;
			this.dgvProduct.EnableHeadersVisualStyles = false;
			this.dgvProduct.Location = new System.Drawing.Point(4, 189);
			this.dgvProduct.MultiSelect = false;
			this.dgvProduct.Name = "dgvProduct";
			this.dgvProduct.ReadOnly = true;
			this.dgvProduct.RowHeadersVisible = false;
			this.dgvProduct.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvProduct.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.dgvProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvProduct.Size = new Size(675, 242);
			this.dgvProduct.TabIndex = 16;
			this.toolTip1.SetToolTip(this.dgvProduct, "Bấm nút phải chuột để chọn\r\nmenu thao tác nhanh !");
			this.btnAddToBill.BackColor = Color.White;
			this.btnAddToBill.Enabled = false;
			this.btnAddToBill.FlatAppearance.BorderColor = Color.FromArgb(192, 255, 255);
			this.btnAddToBill.FlatStyle = FlatStyle.Flat;
			this.btnAddToBill.Location = new System.Drawing.Point(12, 967);
			this.btnAddToBill.Name = "btnAddToBill";
			this.btnAddToBill.Size = new Size(140, 26);
			this.btnAddToBill.TabIndex = 200;
			this.btnAddToBill.Text = "Thêm sản phẩm  [ F3 ]";
			this.btnAddToBill.UseVisualStyleBackColor = false;
			this.toolTip1.IsBalloon = true;
			this.lblCountBill.BackColor = Color.White;
			this.lblCountBill.BorderStyle = BorderStyle.Fixed3D;
			this.lblCountBill.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.lblCountBill.ForeColor = SystemColors.MenuText;
			this.lblCountBill.Location = new System.Drawing.Point(4, 165);
			this.lblCountBill.Name = "lblCountBill";
			this.lblCountBill.Size = new Size(675, 21);
			this.lblCountBill.TabIndex = 564;
			this.lblCountBill.TextAlign = ContentAlignment.MiddleCenter;
			this.txtID.BackColor = Color.White;
			this.txtID.CharacterCasing = CharacterCasing.Upper;
			this.txtID.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.txtID.Location = new System.Drawing.Point(237, 412);
			this.txtID.Name = "txtID";
			this.txtID.ReadOnly = true;
			this.txtID.Size = new Size(100, 22);
			this.txtID.TabIndex = 566;
			this.txtNote.BackColor = Color.White;
			this.txtNote.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.txtNote.Location = new System.Drawing.Point(4, 437);
			this.txtNote.Name = "txtNote";
			this.txtNote.ReadOnly = true;
			this.txtNote.Size = new Size(579, 22);
			this.txtNote.TabIndex = 567;
			this.productName.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.productName.DataPropertyName = "productName";
			this.productName.HeaderText = "Tên thuốc";
			this.productName.MinimumWidth = 200;
			this.productName.Name = "productName";
			this.productName.ReadOnly = true;
			this.productName.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.productName.Width = 200;
			this.productUnit.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.productUnit.DataPropertyName = "productUnit";
			this.productUnit.HeaderText = "Đơn vị tính";
			this.productUnit.MinimumWidth = 90;
			this.productUnit.Name = "productUnit";
			this.productUnit.ReadOnly = true;
			this.productUnit.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.productUnit.Width = 90;
			this.productNumber.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.productNumber.DataPropertyName = "productNumber";
			dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle3.Format = "N0";
			dataGridViewCellStyle3.NullValue = null;
			this.productNumber.DefaultCellStyle = dataGridViewCellStyle3;
			this.productNumber.HeaderText = "Số lượng";
			this.productNumber.MinimumWidth = 80;
			this.productNumber.Name = "productNumber";
			this.productNumber.ReadOnly = true;
			this.productNumber.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.productNumber.Width = 80;
			this.ProductID.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.ProductID.DataPropertyName = "ProductID";
			this.ProductID.HeaderText = "Mã sản phẩm";
			this.ProductID.Name = "ProductID";
			this.ProductID.ReadOnly = true;
			this.ProductID.Visible = false;
			this.ProductGuide.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.ProductGuide.DataPropertyName = "ProductGuide";
			this.ProductGuide.HeaderText = "Liều dùng";
			this.ProductGuide.MinimumWidth = 100;
			this.ProductGuide.Name = "ProductGuide";
			this.ProductGuide.ReadOnly = true;
			this.billID.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.billID.DataPropertyName = "ID";
			this.billID.HeaderText = "Đơn thuốc";
			this.billID.MinimumWidth = 200;
			this.billID.Name = "billID";
			this.billID.ReadOnly = true;
			this.billID.Width = 200;
			this.Note.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Note.DataPropertyName = "Note";
			this.Note.HeaderText = "Diễn giải";
			this.Note.Name = "Note";
			this.Note.ReadOnly = true;
			this.DateCreate.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.DateCreate.DataPropertyName = "DateCreate";
			dataGridViewCellStyle4.Format = "D";
			dataGridViewCellStyle4.NullValue = null;
			this.DateCreate.DefaultCellStyle = dataGridViewCellStyle4;
			this.DateCreate.HeaderText = "Ngày lập";
			this.DateCreate.MinimumWidth = 88;
			this.DateCreate.Name = "DateCreate";
			this.DateCreate.ReadOnly = true;
			this.DateCreate.Visible = false;
			this.DateCreate.Width = 88;
			this.DeseaseID.DataPropertyName = "DeseaseID";
			this.DeseaseID.HeaderText = "Loại bệnh";
			this.DeseaseID.Name = "DeseaseID";
			this.DeseaseID.ReadOnly = true;
			this.DeseaseID.Visible = false;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(684, 466);
			base.Controls.Add(this.txtNote);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.dgvProduct);
			base.Controls.Add(this.dgvBill);
			base.Controls.Add(this.btnAddToBill);
			base.Controls.Add(this.lblCountBill);
			base.Controls.Add(this.txtID);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			this.MaximumSize = new Size(700, 500);
			this.MinimumSize = new Size(700, 500);
			base.Name = "frmFindTmpPrescription";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "..: TÌM KIẾM ĐƠN THUỐC";
			base.Load += new EventHandler(this.frmOutputRetail_Load);
			base.KeyDown += new KeyEventHandler(this.frmOutputRetail_KeyDown);
			((ISupportInitialize)this.dgvBill).EndInit();
			((ISupportInitialize)this.dgvProduct).EndInit();
			base.ResumeLayout(false);
			base.PerformLayout();
		}
		public frmFindTmpPrescription()
		{
			this.InitializeComponent();
		}
		private void frmOutputRetail_Load(object sender, EventArgs e)
		{
			this.getBill();
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			this.OK = false;
			base.Close();
		}
		private void frmOutputRetail_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}
		private void btnEdit_Click(object sender, EventArgs e)
		{
			this.EnableControl(true);
		}
		private void EnableControl(bool Act)
		{
			this.txtNote.ReadOnly = !Act;
			this.btnAddToBill.Enabled = Act;
		}
		private void btnDel_Click(object sender, EventArgs e)
		{
			if (this.txtID.Text.Trim() != "-:-")
			{
				if (MessageBox.Show("Bạn có chắc chắn muốn xoá đơn thuốc [ " + this.txtID.Text.ToUpper() + " ] không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
				{
					this.objDoctor.delTmpPrescription(this.txtID.Text);
					this.EnableControl(true);
					this.txtID.Text = "-:-";
					this.getBill();
				}
			}
		}
		private void txtProductName_TextChanged(object sender, EventArgs e)
		{
		}
		private void getBill()
		{
			try
			{
				this.txtNote.Text = "";
				this.dgvBill.AutoGenerateColumns = false;
				this.dgvProduct.DataSource = null;
				this.dgvProduct.AutoGenerateColumns = false;
				SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
				string cmdText;
				if (this.currDeseaseName.Trim() != "")
				{
					cmdText = "SELECT * FROM [TabTmpPrescription] WHERE UPPER([Note]) LIKE N'%" + this.currDeseaseName + "%' ORDER BY [DateCreate], [ID] DESC";
				}
				else
				{
					cmdText = "SELECT * FROM [TabTmpPrescription] ORDER BY [DateCreate], [ID] DESC";
				}
				SqlCommand selectCommand = new SqlCommand(cmdText, sqlConnection);
				SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
				DataSet dataSet = new DataSet();
				sqlConnection.Open();
				sqlDataAdapter.Fill(dataSet);
				this.dgvBill.DataSource = dataSet.Tables[0];
				this.lblCountBill.Text = "Hiện có : " + dataSet.Tables[0].Rows.Count.ToString() + " đơn thuốc";
				sqlConnection.Close();
				sqlConnection.Dispose();
				sqlDataAdapter.Dispose();
				dataSet.Dispose();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		private void txtProductUnit_TextChanged(object sender, EventArgs e)
		{
		}
		private void txtProductNumber_TextChanged(object sender, EventArgs e)
		{
		}
		private void dgvBill_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			try
			{
				this.objProductTable = new DataTable();
				this.txtID.Text = this.dgvBill.Rows[e.RowIndex].Cells["billID"].Value.ToString();
				this.txtNote.Text = this.dgvBill.Rows[e.RowIndex].Cells["Note"].Value.ToString();
				this.objProductTable = this.objDoctor.getTmpPrescriptionDetail(this.txtID.Text);
				this.dgvProduct.DataSource = this.objProductTable;
				this.txtNote.ReadOnly = true;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		private void cbbPacket_SelectedIndexChanged(object sender, EventArgs e)
		{
		}
		private void dtpSelectMonth_ValueChanged(object sender, EventArgs e)
		{
		}
		private void txtBarcode_TextChanged(object sender, EventArgs e)
		{
		}
		private void btnSearch_Click(object sender, EventArgs e)
		{
		}
		private void btnViewAll_Click(object sender, EventArgs e)
		{
		}
		private void txtProductMoney_Leave(object sender, EventArgs e)
		{
			this.objFunc.txtObject_Leave(sender);
		}
		private void txtBalancer_Leave(object sender, EventArgs e)
		{
			this.objFunc.txtObject_Leave(sender);
		}
		private void txtTotalMoney_Leave(object sender, EventArgs e)
		{
			this.objFunc.txtObject_Leave(sender);
		}
		private void txtTotalMoney_TextChanged(object sender, EventArgs e)
		{
			this.objFunc.txtObject_Leave(sender);
		}
		private void btnListUnit_Click(object sender, EventArgs e)
		{
		}
		private void txtBarcode_KeyDown(object sender, KeyEventArgs e)
		{
		}
		private void txtProductName_KeyPress(object sender, KeyPressEventArgs e)
		{
		}
		private void txtProductNumber_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.btnAddToBill.PerformClick();
			}
		}
		private void txtNote_KeyPress(object sender, KeyPressEventArgs e)
		{
		}
		private void txtID_Enter(object sender, EventArgs e)
		{
			this.txtID.BackColor = Color.Aqua;
		}
		private void txtID_Leave(object sender, EventArgs e)
		{
			this.txtID.BackColor = Color.White;
		}
		private void txtProductPrice_Enter(object sender, EventArgs e)
		{
		}
		private void txtProductPrice_Leave(object sender, EventArgs e)
		{
		}
		private void btnSearchTime_Click(object sender, EventArgs e)
		{
			this.getBill();
		}
		private void txtMoney_TextChanged(object sender, EventArgs e)
		{
		}
		private void txtDiscountOut_TextChanged(object sender, EventArgs e)
		{
		}
		private void txtMoneyAfterDiscount_Leave(object sender, EventArgs e)
		{
		}
		private void txtProductGuide_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Return)
			{
				this.btnAddToBill.PerformClick();
			}
		}
		private int checkInObjTable(string Pid)
		{
			int num = -1;
			int result;
			for (int i = 0; i < this.objProductTable.Rows.Count; i++)
			{
				if (this.objProductTable.Rows[i]["ProductID"].ToString() == Pid)
				{
					result = i;
					return result;
				}
			}
			result = num;
			return result;
		}
		public string getUsageProduct(string Pid)
		{
			string result = "";
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Usage] FROM [TabProducts] WHERE [Pid] = " + Pid, sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = sqlDataReader["Usage"].ToString();
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		private void UpdateUsageProduct(string tmpID, string Usage)
		{
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = new SqlCommand("UpdateUsageOfProduct", sqlConnection);
			sqlCommand.CommandType = CommandType.StoredProcedure;
			sqlCommand.Parameters.Add("PID", SqlDbType.Int);
			sqlCommand.Parameters.Add("Usage", SqlDbType.NVarChar, 2000);
			sqlCommand.Parameters["PID"].Value = tmpID;
			sqlCommand.Parameters["Usage"].Value = Usage;
			sqlCommand.ExecuteNonQuery();
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		private void dgvBill_DoubleClick(object sender, EventArgs e)
		{
			this.OK = true;
			base.Close();
		}
	}
}
